package com.heima.article.controller.v1;

import com.heima.article.service.ArticleService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/v1/article/")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping("load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        return articleService.load(dto,1);
    }

    @PostMapping("loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto){
        return articleService.load(dto,2);
    }

    @PostMapping("loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto){
        return articleService.load(dto,3);
    }

    /**
     * 保存文章三剑客
     * @param dto
     * @return
     */
    @PostMapping("save")
    public ResponseResult saveAll(@RequestBody ArticleDto dto){
        return articleService.saveAll(dto);
    };

}
